package hsl.study.controller;


import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * @Description:
 * @Author: hsl
 * @CreateDate: 2025/7/28 15:40
 * @Version: 1.0
 */

@RestController
@RequestMapping("/deepSeek")
public class DeepSeekController {
    //v1 版本
    @Resource
    private DeepSeekChatModel deepSeekChatModel;

    //v2 版本
    // builder 模式 构造
    private ChatClient chatClient;
    public DeepSeekController(DeepSeekChatModel deepSeekChatModel){
        this.chatClient = ChatClient.builder(deepSeekChatModel).build();
    }
    
    //v3 
    @Resource
    private ChatModel chatModel;
    
    @GetMapping("/chat1")
    public String chat1(@RequestParam(name = "question",defaultValue = "你是谁") String question){
        String result = deepSeekChatModel.call(question);
        System.out.println("result = " + result);
        return LocalDate.now().toString() + "<br> \t" +result; 
    }
    
    @GetMapping(value = "/chat2")
    public String chat2(@RequestParam(name = "question",defaultValue = "你是谁") String question){
        ChatResponse chatResponse = chatClient.prompt(question).call().chatResponse();
        String result = chatResponse.getResult().getOutput().getText();
        System.out.println("result = " + result);
        return LocalDate.now().toString() + "<br> \t" +result;
    }
    @GetMapping("/chat3")
    public String chat3(@RequestParam(name = "question",defaultValue = "你是谁") String question){
        String result = chatModel.call(question);
        return LocalDate.now().toString() + "<br> \t" +result;
    }
}
